Skip to content

test: add unit tests for Shell tool on Windows#349

Closed
stdrc wants to merge 6 commits into
mainfrom
rc/cmd-test-windows
Closed

test: add unit tests for Shell tool on Windows#349
stdrc wants to merge 6 commits into
mainfrom
rc/cmd-test-windows

Conversation

@stdrc

@stdrc stdrc commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

Related Issue

Resolve #(issue_number)

Description

Signed-off-by: Richard Chien <stdrc@outlook.com>
Copilot AI review requested due to automatic review settings November 21, 2025 11:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds unit tests for the Shell tool specifically for Windows cmd, complementing the existing bash tests in test_bash.py. The tests verify that the Shell tool's core functionality works correctly on Windows using cmd syntax instead of bash.

  • Adds 5 test cases covering basic cmd operations: simple commands, error handling, command chaining, environment variables, and file operations
  • Uses platform-specific skipif decorator to ensure tests only run on Windows
  • Follows existing test conventions using inline_snapshot and the same fixture pattern as bash tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_cmd.py
@pytest.mark.asyncio
async def test_command_with_error(shell_tool: Shell):
"""Failing commands should return a ToolError with exit code info."""
result = await shell_tool(Params(command='python -c "import sys; sys.exit(1)"'))

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This test assumes Python is available in the PATH on Windows. For more robust testing, consider using a built-in Windows command that's guaranteed to fail, such as dir C:\nonexistent\directory (similar to the bash test using ls /nonexistent/directory). This would make the test more portable and not dependent on Python being installed.

Suggested change
result = await shell_tool(Params(command='python -c "import sys; sys.exit(1)"'))
result = await shell_tool(Params(command='dir C:\\nonexistent\\directory'))

Copilot uses AI. Check for mistakes.
Comment thread tests/test_cmd.py
@@ -0,0 +1,72 @@
"""Basic Windows cmd tests for the shell tool."""

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The module docstring says "Basic Windows cmd tests" but test_bash.py uses "Tests for the shell tool." For consistency, consider using a similar format like "Tests for the shell tool on Windows." or "Windows cmd tests for the shell tool."

Suggested change
"""Basic Windows cmd tests for the shell tool."""
"""Tests for the shell tool on Windows."""

Copilot uses AI. Check for mistakes.
Comment thread tests/test_cmd.py Outdated
"""Basic file write/read using cmd redirection."""
file_path = temp_work_dir / "test_file.txt"

create_result = await shell_tool(Params(command=f'echo Test content > "{file_path}"'))

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] For consistency with the bash tests (test_bash.py:125), consider using quotes around the content in the echo command. The bash version uses echo 'Test content', so the Windows equivalent should be echo "Test content" > "{file_path}". This makes the test more explicit and consistent across platforms, even though the current version may work.

Suggested change
create_result = await shell_tool(Params(command=f'echo Test content > "{file_path}"'))
create_result = await shell_tool(Params(command=f'echo "Test content" > "{file_path}"'))

Copilot uses AI. Check for mistakes.
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
@stdrc

stdrc commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

Close in favor of #431

@stdrc stdrc closed this Dec 4, 2025
@stdrc stdrc deleted the rc/cmd-test-windows branch December 6, 2025 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants